﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls">

    <Style TargetType="{x:Type Controls:ToggleSwitchButton}">
        <Setter Property="IsTabStop"
                Value="False" />
        <Setter Property="SwitchForeground"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ToggleSwitchButton}">
                    <Border x:Name="Root"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Opacity="{TemplateBinding Opacity}"
                            Padding="{TemplateBinding Padding}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="disabled">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="disabledTumb">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="hover">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="pressed">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CheckStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition GeneratedDuration="0:0:0.05"
                                                      To="Unchecked" />
                                    <VisualTransition GeneratedDuration="0:0:0.05"
                                                      To="Checked">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0:0:0.05"
                                                             To="47"
                                                             Storyboard.TargetProperty="(TranslateTransform.X)"
                                                             Storyboard.TargetName="SwitchThumbTranslate">
                                                <DoubleAnimation.EasingFunction>
                                                    <CircleEase EasingMode="EaseIn" />
                                                </DoubleAnimation.EasingFunction>
                                            </DoubleAnimation>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Checked">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="BackgroundTranslation"
                                                         Storyboard.TargetProperty="(TranslateTransform.X)"
                                                         Duration="0"
                                                         To="68">
                                            <DoubleAnimation.EasingFunction>
                                                <ExponentialEase Exponent="15"
                                                                 EasingMode="EaseOut" />
                                            </DoubleAnimation.EasingFunction>
                                        </DoubleAnimation>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)"
                                                                       Storyboard.TargetName="SwitchThumb">
                                            <EasingDoubleKeyFrame KeyTime="0"
                                                                  Value="47" />
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Dragging" />
                                <VisualState x:Name="Unchecked">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="BackgroundTranslation"
                                                         Storyboard.TargetProperty="(TranslateTransform.X)"
                                                         Duration="0"
                                                         To="0" />
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)"
                                                                       Storyboard.TargetName="border">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ThicknessAnimation Duration="0"
                                                            To="1"
                                                            Storyboard.TargetProperty="(Border.Margin)"
                                                            Storyboard.TargetName="checked" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid x:Name="SwitchRoot"
                              Background="{x:Null}"
                              Height="Auto"
                              Width="Auto"
                              UseLayoutRounding="True">
                            <Grid x:Name="SwitchTrack"
                                  Width="Auto">
                                <Grid x:Name="SwitchBottom"
                                      Height="25"
                                      Width="60">
                                    <Rectangle x:Name="SwitchBackground"
                                               Width="Auto"
                                               Height="Auto"
                                               HorizontalAlignment="Stretch"
                                               VerticalAlignment="Stretch">
                                        <Rectangle.RenderTransform>
                                            <TranslateTransform x:Name="BackgroundTranslation" />
                                        </Rectangle.RenderTransform>
                                    </Rectangle>
                                    <Border BorderThickness="2"
                                            BorderBrush="{DynamicResource GrayBrush4}">
                                        <Grid Margin="2">
                                            <Border x:Name="checked"
                                                    BorderThickness="0"
                                                    Background="{TemplateBinding SwitchForeground}"
                                                    Margin="0" />
                                            <Border x:Name="border"
                                                    BorderThickness="0"
                                                    Background="{DynamicResource GrayBrush4}"
                                                    Visibility="Collapsed"
                                                    Margin="0" />
                                            <Border x:Name="pressed"
                                                    BorderThickness="0"
                                                    Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                                    Opacity="0.25"
                                                    Visibility="Collapsed"
                                                    Margin="0" />
                                            <Border x:Name="hover"
                                                    BorderThickness="0"
                                                    Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                                    Opacity="0.15"
                                                    Visibility="Collapsed"
                                                    Margin="0" />
                                            <Border x:Name="disabled"
                                                    BorderThickness="0"
                                                    Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"
                                                    Opacity="0.5"
                                                    Visibility="Collapsed"
                                                    Margin="0" />
                                        </Grid>
                                    </Border>
                                </Grid>
                                <Border x:Name="SwitchThumb"
                                        BorderBrush="{TemplateBinding Background}"
                                        BorderThickness="0"
                                        Margin="0"
                                        Width="13"
                                        Height="Auto"
                                        HorizontalAlignment="Left">
                                    <Border.RenderTransform>
                                        <TransformGroup>
                                            <ScaleTransform />
                                            <SkewTransform />
                                            <RotateTransform />
                                            <TranslateTransform x:Name="SwitchThumbTranslate" />
                                        </TransformGroup>
                                    </Border.RenderTransform>
                                    <Grid>
                                        <Border x:Name="ThumbCenter"
                                                BorderBrush="{TemplateBinding Foreground}"
                                                BorderThickness="0"
                                                Background="{DynamicResource BlackBrush}" />
                                        <Border x:Name="disabledTumb"
                                                BorderBrush="{TemplateBinding Foreground}"
                                                BorderThickness="0"
                                                Background="{DynamicResource WhiteBrush}"
                                                Opacity="0.5"
                                                Visibility="Collapsed" />
                                    </Grid>
                                </Border>
                            </Grid>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:ToggleSwitch}">
        <Setter Property="IsTabStop"
                Value="True" />
        <Setter Property="SwitchForeground"
                Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="Foreground"
                Value="{DynamicResource BlackBrush}" />
        <Setter Property="FontFamily"
                Value="Segoe UI Semibold" />
        <Setter Property="FontSize"
                Value="14.667" />
        <Setter Property="HeaderTemplate">
            <Setter.Value>
                <DataTemplate>
                    <TextBlock Text="{Binding Mode=OneWay}"
                               TextWrapping="Wrap"
                               FontWeight="Normal"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Top"
                               Margin="0,0,0,5"
                               Opacity="0.65"
                               FontSize="16" />
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:ToggleSwitch}">
                    <Border BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="Header"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Duration="0"
                                                         To="0.3" />
                                        <DoubleAnimation Storyboard.TargetName="Content"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Duration="0"
                                                         To="0.3" />
                                        <DoubleAnimation Storyboard.TargetName="Switch"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Duration="0"
                                                         To="0.75" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"
                                                  x:Name="firstCol" />
                                <ColumnDefinition Width="Auto"
                                                  x:Name="secCol" />
                            </Grid.ColumnDefinitions>
                            <ContentControl x:Name="Header"
                                            Grid.ColumnSpan="2"
                                            Content="{TemplateBinding Header}"
                                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                                            IsTabStop="False" />
                            <ContentControl x:Name="Content"
                                            Grid.Row="1"
                                            Content="{TemplateBinding Content}"
                                            ContentTemplate="{TemplateBinding ContentTemplate}"
                                            IsTabStop="False"
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                            FontFamily="{TemplateBinding FontFamily}"
                                            FontSize="{TemplateBinding FontSize}" />
                            <Controls:ToggleSwitchButton x:Name="Switch"
                                                         Grid.Column="1"
                                                         Grid.Row="1"
                                                         Background="{TemplateBinding Background}"
                                                         SwitchForeground="{TemplateBinding SwitchForeground}"
                                                         VerticalAlignment="Center" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Header}"
                                     Value="{x:Null}">
                            <Setter TargetName="Header"
                                    Property="Visibility"
                                    Value="Collapsed" />
                        </DataTrigger>
                        <Trigger Property="ContentDirection"
                                 Value="RightToLeft">
                            <Setter Property="HorizontalContentAlignment"
                                    Value="Right" />
                            <Setter TargetName="firstCol"
                                    Property="Width"
                                    Value="Auto" />
                            <Setter TargetName="secCol"
                                    Property="Width"
                                    Value="*" />
                            <Setter TargetName="Content"
                                    Property="Grid.Column"
                                    Value="1" />
                            <Setter TargetName="Switch"
                                    Property="Grid.Column"
                                    Value="0" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
